#pragma once
#include <cassert>

namespace XyNet
{
	namespace SetMapHelper
	{
		template <typename ContainerType, typename KeyType>
		inline void insert(ContainerType* set, const KeyType& key)
		{
			pair<typename ContainerType::iterator, bool> result = set->insert(key);
			assert(result.second && "The key already exist.");
		}

		template <typename MapType, typename KeyType, typename ValueType>
		inline void insert(MapType* map, const KeyType& key, const ValueType& value)
		{
			pair<typename MapType::iterator, bool> result = map->insert(make_pair(key, value));
			assert(result.second && "The key already exist.");
		}

		template <typename ContainerType, typename KeyType>
		inline void erase(ContainerType* setMap, const KeyType& key)
		{
			typename ContainerType::iterator it = setMap->find(key);
			assert(it != setMap->end() && "Can not find the key.");
			setMap->erase(it);
		}

		template <typename ContainerType, typename KeyType>
		inline bool has(const ContainerType* setMap, const KeyType& key)
		{
			typename ContainerType::const_iterator it = setMap->find(key);
			if (it != setMap->end())
				return true;
			else
				return false;
		}

		template <typename MapType, typename KeyType>
		inline const typename MapType::mapped_type& getValue(const MapType* map, const KeyType& key)
		{
			typename MapType::const_iterator it = map->find(key);
			assert(it != map->end() && "Can not find the key.");
			return it->second;
		}

		template <typename MapType, typename KeyType, typename ValueType>
		inline void setValue(MapType* map, const KeyType& key, const ValueType& val)
		{
			typename MapType::iterator it = map->find(key);
			if (it != map->end() && "Can not find the key.");
			it->second = val;
		}
	}
}